home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
526-550
/
disk_534
/
term
/
source.lzh
/
SerialPanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-06
|
15KB
|
546 lines
/* $Revision Header * Header built automatically - do not edit! *************
*
* (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
*
* Name .....: SerialPanel.c
* Created ..: Monday 21-Jan-91 20:12
* Revision .: 0
*
* Date Author Comment
* ========= ======== ====================
* 21-Jan-91 Olsen Created this file!
*
* $Revision Header ********************************************************/
#include "TermGlobal.h"
enum { GAD_BAUD,GAD_DATABITS,GAD_PARITY,GAD_STOPBITS,GAD_HANDSHAKING,GAD_DUPLEX,
GAD_HIGHSPEED,GAD_BREAKLENGTH,GAD_DEVICE,GAD_UNIT,GAD_USE,GAD_CANCEL };
#define WIDTH 335
#define HEIGHT 159
STATIC LONG Bauds[12] =
{
110,300,1200,2400,4800,9600,19200,31250,38400,57600,76800,115200
};
STATIC STRPTR DataBits[3] =
{
(STRPTR)"Seven",
(STRPTR)"Eight",
NULL
};
STATIC STRPTR Parity[6] =
{
(STRPTR)"None",
(STRPTR)"Even",
(STRPTR)"Odd",
(STRPTR)"Mark",
(STRPTR)"Space",
NULL
};
STATIC STRPTR StopBits[3] =
{
(STRPTR)"One",
(STRPTR)"Two",
NULL
};
STATIC STRPTR Handshaking[4] =
{
(STRPTR)"XON/XOFF",
(STRPTR)"RTS/CTS",
(STRPTR)"None",
NULL
};
STATIC STRPTR Duplex[3] =
{
(STRPTR)"Full",
(STRPTR)"Half (Local Echo)",
NULL
};
enum { MEN_BAUD=1,MEN_DATABITS,MEN_PARITY,MEN_STOPBITS,MEN_HANDSHAKING,
MEN_DUPLEX,MEN_HIGHSPEED,MEN_USE,MEN_CANCEL,MEN_QUITPANEL };
STATIC struct NewMenu SerialMenu[] =
{
{ NM_TITLE, "Project", 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Baud Rate", "R", 0, 0, (APTR)MEN_BAUD},
{ NM_ITEM, "Bits/Char", "B", 0, 0, (APTR)MEN_DATABITS},
{ NM_ITEM, "Parity", "P", 0, 0, (APTR)MEN_PARITY},
{ NM_ITEM, "Stop Bits", "S", 0, 0, (APTR)MEN_STOPBITS},
{ NM_ITEM, "Handshaking", "H", 0, 0, (APTR)MEN_HANDSHAKING},
{ NM_ITEM, "Duplex", "D", 0, 0, (APTR)MEN_DUPLEX},
{ NM_ITEM, "High Speed Mode", "M", 0, 0, (APTR)MEN_HIGHSPEED},
{ NM_ITEM, NM_BARLABEL, 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Use", "U", 0, 0, (APTR)MEN_USE},
{ NM_ITEM, "Cancel", "C", 0, 0, (APTR)MEN_CANCEL},
{ NM_ITEM, NM_BARLABEL, 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Quit", "Q", 0, 0, (APTR)MEN_QUITPANEL},
{ NM_END, 0, 0 , 0, 0, (APTR)0}
};
STATIC LONG __saveds
ShowBaud(struct Gadget *SomeGadget,WORD Level)
{
return(Bauds[Level]);
}
STATIC struct Gadget *
CreateAllGadgets(struct Configuration *Config,struct Gadget **GadgetArray,struct Gadget **GadgetList,APTR VisualInfo,UWORD TopEdge)
{
struct Gadget *Gadget;
struct NewGadget NewGadget;
UWORD Counter = 0;
SHORT i,Rate;
if(Gadget = CreateContext(GadgetList))
{
for(i = 0 ; i < 13 ; i++)
{
if(Config -> BaudRate == Bauds[i])
{
Rate = i;
break;
}
}
NewGadget . ng_Width = 164;
NewGadget . ng_Height = 12;
NewGadget . ng_GadgetText = " Baud _Rate ";
NewGadget . ng_TextAttr = &DefaultFont;
NewGadget . ng_VisualInfo = VisualInfo;
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = NG_HIGHLABEL;
NewGadget . ng_LeftEdge = (strlen(NewGadget . ng_GadgetText) + 2 - 1) * 8 + 1;
NewGadget . ng_TopEdge = 1 + TopEdge;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTSL_Min, 0,
GTSL_Max, 11,
GTSL_Level, Rate,
GTSL_DispFunc, ShowBaud,
GTSL_LevelFormat, "%6ld",
GTSL_MaxLevelLen, 6,
TAG_DONE);
NewGadget . ng_GadgetText = "_Bits/Char";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 4;
GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTCY_Labels, DataBits,
GTCY_Active, Config -> BitsPerChar - 7,
TAG_DONE);
NewGadget . ng_GadgetText = "_Parity";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 1;
GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTCY_Labels, Parity,
GTCY_Active, Config -> Parity,
TAG_DONE);
NewGadget . ng_GadgetText = "_Stop Bits";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 1;
GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTCY_Labels, StopBits,
GTCY_Active, Config -> StopBits - 1,
TAG_DONE);
NewGadget . ng_GadgetText = "_Handshaking";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 1;
GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTCY_Labels, Handshaking,
GTCY_Active, Config -> Handshaking,
TAG_DONE);
NewGadget . ng_GadgetText = "_Duplex";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 1;
GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTCY_Labels, Duplex,
GTCY_Active, Config -> Duplex,
TAG_DONE);
NewGadget . ng_GadgetText = "High-Speed _Mode";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTCB_Checked, Config -> HighSpeed,
TAG_DONE);
NewGadget . ng_GadgetText = "Break Length (µs)";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
GTIN_MaxChars, 8,
GTIN_Number, Config -> BreakLength,
TAG_DONE);
NewGadget . ng_GadgetText = "Serial Device";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 4;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars, 40,
GTST_String, Config -> SerialDevice,
TAG_DONE);
NewGadget . ng_GadgetText = "Device Unit Number";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
GTIN_MaxChars, 2,
GTIN_Number, Config -> UnitNumber,
TAG_DONE);
NewGadget . ng_Width = 52;
NewGadget . ng_Height = 12;
NewGadget . ng_GadgetText = "_Use";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = 0;
NewGadget . ng_LeftEdge = 10;
NewGadget . ng_TopEdge = HEIGHT - 3 - NewGadget . ng_Height;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
NewGadget . ng_GadgetText = "_Cancel";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = WIDTH - 10 - NewGadget . ng_Width;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
}
DubGadList(GadgetArray[0]);
return(Gadget);
}
BYTE
SerialPanel(struct Configuration *Config)
{
struct Window *PanelWindow;
struct Menu *PanelMenu;
struct Gadget *GadgetList;
struct Gadget *GadgetArray[GAD_CANCEL + 1];
LONG i;
CopyMem(Config,&PrivateConfig,sizeof(struct Configuration));
if(CreateAllGadgets(Config,&GadgetArray[0],&GadgetList,VisualInfo,Screen -> WBorTop + Screen -> Font -> ta_YSize + 1))
{
if(PanelMenu = CreateMenus(SerialMenu,
GTMN_FrontPen, 0,
TAG_DONE))
{
if(LayoutMenus(PanelMenu,VisualInfo,
GTMN_TextAttr,&DefaultFont,
TAG_DONE))
{
if(PanelWindow = OpenWindowTags(NULL,
WA_Left, (Screen -> Width - WIDTH) >> 1,
WA_Top, (Screen -> Height - HEIGHT) >> 1,
WA_Width, WIDTH,
WA_Height, HEIGHT,
WA_Activate, TRUE,
WA_DragBar, TRUE,
WA_DepthGadget, TRUE,
WA_RMBTrap, TRUE,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_CustomScreen,Screen,
WA_IDCMP, IDCMP_GADGETDOWN | IDCMP_ACTIVEWINDOW | IDCMP_CLOSEWINDOW | SLIDERIDCMP | CHECKBOXIDCMP | LISTVIEWIDCMP | IDCMP_MENUPICK | IDCMP_RAWKEY,
WA_Title, "Serial Preferences",
TAG_DONE))
{
struct IntuiMessage *Massage;
ULONG Class,Code,Value;
struct Gadget *Gadget;
BYTE Terminated = FALSE;
PushWindow(PanelWindow);
AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
GT_RefreshWindow(PanelWindow,NULL);
SetMenuStrip(PanelWindow,PanelMenu);
PanelWindow -> Flags &= ~WFLG_RMBTRAP;
ActivateGadget(GadgetArray[GAD_BREAKLENGTH],PanelWindow,NULL);
ActiveGadget = GadgetArray[GAD_BREAKLENGTH];
while(!Terminated)
{
WaitPort(PanelWindow -> UserPort);
while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
{
Class = Massage -> Class;
Code = Massage -> Code;
Gadget = (struct Gadget *)Massage -> IAddress;
GT_ReplyIMsg(Massage);
if(Class == IDCMP_GADGETDOWN)
{
if((Gadget -> GadgetType & GTYP_GTYPEMASK) == STRGADGET)
ActiveGadget = Gadget;
}
if(Class == IDCMP_ACTIVEWINDOW && ActiveGadget)
ActivateGadget(ActiveGadget,PanelWindow,NULL);
if(Class == IDCMP_RAWKEY)
{
if(Code == IECODE_UP_PREFIX|103 && CommandWindow == PanelWindow)
ActivateGadget(CommandGadget,PanelWindow,NULL);
}
if(Class == IDCMP_MENUPICK)
{
struct MenuItem *MenuItem;
while(Code != MENUNULL)
{
MenuItem = ItemAddress(PanelMenu,Code);
switch((ULONG)MENU_USERDATA(MenuItem))
{
case MEN_QUITPANEL: Class = IDCMP_CLOSEWINDOW;
break;
case MEN_BAUD: if(Config -> BaudRate == Bauds[11])
Value = 0;
else
{
for(i = 0 ; i < 13 ; i++)
{
if(Config -> BaudRate == Bauds[i])
{
Value = i + 1;
break;
}
}
}
GT_SetGadgetAttrs(GadgetArray[GAD_BAUD],PanelWindow,NULL,
GTSL_Level,Value,
TAG_DONE);
Config -> BaudRate = Bauds[Value];
break;
case MEN_DATABITS: if(Config -> BitsPerChar == 8)
Value = 0;
else
Value = 1;
GT_SetGadgetAttrs(GadgetArray[GAD_DATABITS],PanelWindow,NULL,
GTCY_Active,Value,
TAG_DONE);
Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_DATABITS];
Code = Value;
goto GadCheck;
case MEN_PARITY: if(Config -> Parity == PARITY_SPACE)
Value = PARITY_NONE;
else
Value = Config -> Parity + 1;
GT_SetGadgetAttrs(GadgetArray[GAD_PARITY],PanelWindow,NULL,
GTCY_Active,Value,
TAG_DONE);
Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_PARITY];
Code = Value;
goto GadCheck;
case MEN_STOPBITS: if(Config -> StopBits == 2)
Value = 0;
else
Value = 1;
GT_SetGadgetAttrs(GadgetArray[GAD_STOPBITS],PanelWindow,NULL,
GTCY_Active,Value,
TAG_DONE);
Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_STOPBITS];
Code = Value;
goto GadCheck;
case MEN_HANDSHAKING: if(Config -> Handshaking == HANDSHAKING_NONE)
Value = HANDSHAKING_XONXOFF;
else
Value = Config -> Handshaking + 1;
GT_SetGadgetAttrs(GadgetArray[GAD_HANDSHAKING],PanelWindow,NULL,
GTCY_Active,Value,
TAG_DONE);
Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_HANDSHAKING];
Code = Value;
goto GadCheck;
case MEN_DUPLEX: if(Config -> Duplex == DUPLEX_FULL)
Value = DUPLEX_HALF;
else
Value = DUPLEX_FULL;
GT_SetGadgetAttrs(GadgetArray[GAD_DUPLEX],PanelWindow,NULL,
GTCY_Active,Value,
TAG_DONE);
Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_DUPLEX];
Code = Value;
goto GadCheck;
case MEN_HIGHSPEED: GT_SetGadgetAttrs(GadgetArray[GAD_HIGHSPEED],PanelWindow,NULL,
GTCB_Checked,GadgetArray[GAD_HIGHSPEED] -> Flags & GFLG_SELECTED ? FALSE : TRUE,
TAG_DONE);
break;
case MEN_USE: Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_USE];
break;
case MEN_CANCEL: Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_CANCEL];
break;
default: break;
}
Code = MenuItem -> NextSelect;
}
if(ActiveGadget)
ActivateGadget(ActiveGadget,PanelWindow,NULL);
}
if(Class == IDCMP_CLOSEWINDOW)
Terminated = TRUE;
if(Class == IDCMP_MOUSEMOVE)
{
switch(Gadget -> GadgetID)
{
case GAD_BAUD: Config -> BaudRate = Bauds[Code];
break;
default: break;
}
}
GadCheck: if(Class == IDCMP_GADGETUP)
{
switch(Gadget -> GadgetID)
{
case GAD_DUPLEX: Config -> Duplex = Code;
break;
case GAD_HANDSHAKING: Config -> Handshaking = Code;
break;
case GAD_STOPBITS: Config -> StopBits = 1 + Code;
break;
case GAD_PARITY: Config -> Parity = Code;
break;
case GAD_DATABITS: Config -> BitsPerChar = 7 + Code;
break;
case GAD_USE: Terminated = TRUE;
Config -> UnitNumber = ((struct StringInfo *)GadgetArray[GAD_UNIT] -> SpecialInfo) -> LongInt;
strcpy(Config -> SerialDevice,((struct StringInfo *)GadgetArray[GAD_DEVICE] -> SpecialInfo) -> Buffer);
Config -> BreakLength = ((struct StringInfo *)GadgetArray[GAD_BREAKLENGTH] -> SpecialInfo) -> LongInt;
Config -> HighSpeed = GadgetArray[GAD_HIGHSPEED] -> Flags & GFLG_SELECTED;
break;
case GAD_CANCEL: Terminated = TRUE;
CopyMem(&PrivateConfig,Config,sizeof(struct Configuration));
break;
default: break;
}
}
}
}
PanelWindow -> Flags |= WFLG_RMBTRAP;
ClearMenuStrip(PanelWindow);
RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
PopWindow();
CloseWindow(PanelWindow);
}
}
FreeMenus(PanelMenu);
}
FreeGadgets(GadgetList);
}
if(memcmp(&PrivateConfig,Config,sizeof(struct Configuration)))
return(TRUE);
else
return(FALSE);
}